package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class reflectDemo5 {
    public static void main(String[] args) throws Exception {
        Person p=new Person();
        p.say("大家好");

        Class cls=Class.forName("reflect.Person");

        Constructor constructor=cls.getConstructor(String.class,int.class);

        Object obj=constructor.newInstance("小王",18);

        Method method=cls.getMethod("say",String.class);

        method.invoke(obj,"大家好我是练习时长两年半的达内练习生小王");

        Method method1=cls.getMethod("say",String.class,int.class);

        method1.invoke(obj,"大家好我是练习时长两年半的达内练习生小王,喜欢唱跳Rap篮球",5);

    }
}
